<template>
  <div class="content">
    <back-bar title="注销账号" @toBack="toBack" />
    <logout-bottom-bar @toLogout="toLogout" />
    <select-popup
      title="您确定注销吗"
      :showSelectPopup="showSelectPopup"
      @handleCancel="handleCancel"
      @handleAffirm="handleAffirm"
      @handleClickOverlay="handleClickOverlay"
    />
  </div>
</template>

<script>
import BackBar from "@/components/conten/backbar/BackBar";
import LogoutBottomBar from "./childcomps/logoutcomps/LogouBottomBar";
import SelectPopup from "components/common/selectpopup/SelectPopup";
import { mapMutations } from "vuex";

import { Logout } from "network/user";

export default {
  name: "logout",
  components: {
    BackBar,
    LogoutBottomBar,
    SelectPopup,
  },
  data() {
    return {
      showSelectPopup: false,
    };
  },
  methods: {
    ...mapMutations({
      getNickName: "moduleUser/getNickName",
      getId: "moduleUser/getId",
      getHeader: "moduleUser/getHeader",
      getBirthday: "moduleUser/getBirthday",
      getEmail: "moduleUser/getEmail",
      getGender: "moduleUser/getGender",
      getTelPhone: "moduleUser/getTelPhone",
      getUserName: "moduleUser/getUserName",
    }),
    toBack() {
      this.$router.back();
    },
    toLogout() {
      this.showSelectPopup = true;
    },
    handleCancel() {
      this.showSelectPopup = false;
    },
    handleAffirm() {
      let id = localStorage.getItem("userId");
      Logout({ id }).then((res) => {
        console.log(res);
        if (res.code == 200) {
          let city = localStorage.getItem("city");
          let staticpath = localStorage.getItem("staticpath");
          let currentRentPath = localStorage.getItem('currentRentPath')
          let currentCity = localStorage.getItem("currentCity")
          localStorage.clear();
          localStorage.setItem("city", city);
          localStorage.setItem("staticpath", staticpath);
          localStorage.setItem("currentRentPath",currentRentPath)
          localStorage.setItem("currentCity",currentCity)
          this.getNickName("");
          this.getBirthday("");
          this.getEmail("");
          this.getGender("");
          this.getTelPhone("");
          this.getUserName("");
          this.getId();
          this.getHeader();
          this.$toast({
            message: "注销成功",
            position: "bottom",
          });
          this.$router.push("/mine");
        } else {
          this.$toast({
            message: "注销失败",
            position: "bottom",
          });
          this.showSelectPopup = false;
        }
      });
      // console.log("在这里可以发送注销的请求");
    },
    handleClickOverlay() {
      this.showSelectPopup = !this.showSelectPopup;
    },
  },
};
</script>

<style scoped>
</style>